package com.hanamaki.oop.demo06;

public class Application_instanceof {

    public static void main(String[] args) {

        /* 测试 instanceof 运算符 */
        /* 判断两个类之间 是否存在  父子关系 */
        /* X与Y是否存在父子关系 */

        /*/* 一个对象的实例类型是确定的 但是可以指向的引用类型就不确定了；  父类的引用指向子类 */

        Object object = new Student();
        System.out.println(object instanceof Student);
        System.out.println(object instanceof Person);
        System.out.println(object instanceof Teacher);
        System.out.println(object instanceof String);

        System.out.println("=================================");
        Person person = new Student();
        System.out.println(person instanceof Student);
        System.out.println(person instanceof Person);
        System.out.println(person instanceof Teacher);
//        System.out.println(person instanceof String); // 编译报错


        System.out.println("======================");
        Student student = new Student();
        System.out.println(student instanceof Student);
        System.out.println(student instanceof Person);
        System.out.println(student instanceof Object);
//        System.out.println(student instanceof Teacher);// 编译报错
//        System.out.println(student instanceof String);// 编译报错
    }
}
